package com.vfa.fishing.object;

import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import com.vfa.fishing.GameActivity;
import com.vfa.fishing.common.Constant;

public class Moss extends AbstractObject {
    public boolean Visible;
    private float  speedX;
    private float  speedY;
    public int kind;
    public int direction;
    public int sideAppear;
    public int iTimer;

    // Constructor
    public Moss (int x,int y,TiledTextureRegion pTextureRegion,int sideApp,int kind) {
        super(x,y,pTextureRegion,sideApp);

        this.kind = kind;
        sideAppear = sideApp;// huong xuat hien cua rong reu

        if (sideAppear == Constant.LEFTSIDE) {

            direction = Constant.RIGHT;

        } else if(sideAppear == Constant.RIGHTSIDE) {

            direction = Constant.LEFT;

        }

        // set van toc di chuyen cua rong reu
        if (kind == 0) {

            speedX = 5;
            speedY = 5;
        } else if (kind == 1) {

            speedX = 10;
            speedY = 10;

        }
        this.kindOfObject = Constant.MOSS;
    }

    public void update() {

        iTimer = GameActivity.TIMER;
        float  X = 0;
        float  Y = 0;
        X = this.getX();
        Y = this.getY();

        if (kind == 0) {
              if (iTimer%20 == 0) {

                   speedX = GameActivity.rand.nextInt(10) + 1;

              }
             if (direction == Constant.LEFT && !this.checkCollision()) {

                 X -= speedX;
                 this.setPosition(X, Y);

             }
             else if (direction == Constant.RIGHT && !checkCollision()) {

                 X += speedX;
                 this.setPosition(X, Y);

             }
        } else if (kind == 1) {
           if (iTimer%30 == 0) {

                speedX = GameActivity.rand.nextInt(10) + 3;

           }
           if(direction == Constant.LEFT && !checkCollision()) {

               X -= speedX;
               this.setPosition(X, Y);

           } else if (direction == Constant.RIGHT && !checkCollision()) {

               X += speedX;
               this.setPosition(X, Y);

           }
        }

    }



    @Override
    public void Eat() {
        // TODO Auto-generated method stub

    }

	@Override
	public void resetDirection() {
		// TODO Auto-generated method stub
		
	}

}
